<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id: TagLibHtml.class.php 2730 2012-02-12 04:45:34Z liu21st $

/**
 +-------------------------------
 * Html标签库驱动
 +-------------------------------
 */
class TagLibTest extends TagLib{
    // 标签定义
    protected $tags   =  array(
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次
        'listselect'           => array('attr'=>'name,id,class,style,title,datatype,url,multiple,selected','close'=>0)
    );
    /**
     +----------------------------------------------------------
     * list标签解析
     * 格式： <html:list datasource="" show="" />
     *
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
    public function _customer($attr) {
        $tag        = $this->parseXmlAttr($attr,'customer');
        $name       = $tag['name'];
		$id         = $tag['id'];
		$class      = $tag['class'];
		$style      = $tag['style'];
		$title      = $tag['title'];
		$datatype   = $tag['datatype'];
		$multiple   = $tag['multiple'] == '' ? 0 : $tag['multiple'];
		$selected   = $tag['selected'] == '' ? 0 : $tag['selected'];
		$url        = $tag['url'];
		//return $url;
		$ret = '<div class="'.$name.'Box"><div class="'.$name.'DataBox">加载中……</div><a href="javascript:void(0);" onClick="_openWindow'.$name.'()">'.$title.'</a></div>';
		$ret .= '<style>.SelectDataListItem .icon-ok-sign{color:#1BAB2B; display:none; font-size:16px !important;}
	.SelectDataListItem .icon-circle-blank{color:#1BAB2B; display:inline-block; color:#eee; font-size:16px !important;}
	.SelectDataListItem.selected .icon-ok-sign{display:inline-block !important; visibility:visible !important;}
	.SelectDataListItem.selected .icon-circle-blank{display:none !important; visibility:hidden !important;}
</style>';
		
		$ret .= '<script>
		
		
		function '.$name.'select(){
		$(".auii_statei_focus'.$name.' .SelectDataListItem").click(function(e) {
				if(!$(this).hasClass("selected")){
					//不允许多选
					
					if('.$multiple.' == 0){
						$(".auii_statei_focus'.$name.' .SelectDataListItem").removeClass("selected");
						$(this).addClass("selected");
						$(this).find(".DataBox input").attr("name", "'.$name.'");
						$(".'.$name.'DataBox").html($(this).find(".DataBox").html());
					}else{
						$(this).addClass("selected");
						//添加数据
						var sval = $(this).find(".DataBox input").val();
						if($(".'.$name.'DataBox input[value=\""+sval+"\"]").length == 0){
							$(this).find(".DataBox input").attr("name", "'.$name.'[]");
							$(".'.$name.'DataBox").append($(this).find(".DataBox").html());
						}
					}
				}else{ 
					$(this).removeClass("selected");
				}
				
			});
		

	}
		
		function '.$name.'PageInit(){
		$(".auii_statei_focus'.$name.' .PagesBox").find("a").each(function(e) {
			var url = $(this).attr("href");
			$(this).attr("href", "javascript:void(0);");
			$(this).attr("rel", url);
			$(this).click(function(e) {
                $.get(url, {}, function(data){
						$(".auii_statei_focus'.$name.' .aui_content").html(data.tbody);
						'.$name.'select(); 
						//绑定分页事件
						'.$name.'PageInit();
					}, "json");
				});
            });
		

	}
		
		
		
		
		if(<?php echo $'.$selected.'; ?> != 0){
			$.get("'.$url.'",{selected:"<?php echo $'.$selected.';?>"},function(data){
				$(".'.$name.'DataBox").html(data.tbody);
				
			},"json");
		}else{
			$(".'.$name.'DataBox").html("");
		} 
		
		function _openWindow'.$name.'(){
		var lock = true;
		var height = $(window).height() - 200;
		var width = 700;
		';
		
		if(isMobile()){
			$ret .= 'width = "100%";
			lock = false;
			var height = $(window).height() - 45;';
		}
		$ret .= 'var mydialog = art.dialog.load("'.$url.'",{init:function(){
			
			$(".aui_state_focus").addClass("auii_statei_focus'.$name.'");
			'.$name.'PageInit();
			';
			if(isMobile()){
			$ret .= '$(".modal-shiftfix").addClass("hidden");
			//弹出窗口后把其它窗口隐藏起来
			$(".auii_statei_focus").hide();
			$("body").addClass("padding0");
			$(".aui_state_focus").addClass("auii_statei_focus auii_statei_focus'.$name.'");
			
			var index = $(".auii_statei_focus").length;
			index ++;
			
			$(".aui_state_focus").attr("index", index);
			
			$(".aui_state_focus").addClass("index"+index);
			
			
			
			
			//插入按钮前要清空原来的按钮
			$(".auii_statei_focus'.$name.' .aui_titleBar button").remove();
			var okBtn = $(".auii_statei_focus'.$name.' .aui_buttons").html();
			$(".auii_statei_focus'.$name.' .aui_buttons").hide();
			$(okBtn).insertAfter(".aui_state_focus .aui_close");
			$(".auii_statei_focus'.$name.' .aui_titleBar button").each(function(index, element) {
                $(this).click(function(e) {
                    $(".auii_statei_focus'.$name.' .aui_buttons button").eq(index).trigger("click");
                });
            });';
		}
			
			$ret .= '
			'.$name.'select();
			//////////////////////////////////
			
		},width: width, height: height,lock:lock,title:"'.$title.'",ok:function(){
			//执行确定
			//$(".auii_statei_focus'.$name.' .selected .DataBox").insertAfter("");
			mydialog.close();
			
			return false;
		},okVal:"确定",close:function(){
			
			';
			
			
		if(isMobile()){
			$ret .= '//关闭窗口后显示其它窗口
			
			//alert($(".auii_statei_focus").length);
			
			//$(".auii_statei_focus").show();alert($(".aui_state_lock:last").length);
			if($(".auii_statei_focus").length > 1){
				//alert($(".aui_state_focus").attr("index")*1 - 1);
				$(".auii_statei_focus.index"+($(".aui_state_focus").attr("index")*1 - 1)).show().addClass("aui_state_focus");
			}else{
				$("html,body").animate({scrollTop:$.cookie("scroll_hidden")},100);
				$(".modal-shiftfix").removeClass("hidden");
				$("body").removeClass("padding0");
			}';
			
		}else{
			
			$ret .= 'if($(".aui_state_lock").length > 0){
			    $(".aui_state_lock.index"+($(".aui_state_focus").attr("index")*1 - 1)).addClass("aui_state_focus");
			}else{
				$("html,body").animate({scrollTop:$.cookie("scroll_hidden")},100);
				$(".modal-shiftfix").removeClass("hidden");
				$("body").removeClass("padding0");
			}';
		}
			
			$ret .= '
			//alert($(".auii_statei_focus:last"));
			
		}, content:"加载中……"});
	}
</script>';
		return $ret;
    }
    
	

}
